﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace ZhangZhao.WebAPI
{
    public partial class UserAvatarCommentEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string s = Output.Fail;

            try
            {
                //string DataValue = HttpUtility.HtmlDecode(HttpContext.Current.Request[Parameter.JsonData]);
                string Command = HttpUtility.HtmlDecode(HttpContext.Current.Request[Parameter.Command]);

                int UserAvatarCommentId; int.TryParse(HttpContext.Current.Request["UserAvatarComment"], out UserAvatarCommentId);
                int UserAvatarId; int.TryParse(HttpContext.Current.Request["UserAvatarId"], out UserAvatarId);
                string CommentUserName = HttpContext.Current.Request["CommentUserName"];
                string CommentBody = HttpContext.Current.Request["CommentBody"];
                bool IsLike = true;
                bool.TryParse(HttpContext.Current.Request[Parameter.IsLike], out IsLike);
                bool IsRecommend = true;
                bool.TryParse(HttpContext.Current.Request[Parameter.IsRecommend], out IsRecommend);
                int Score = 0;
                int.TryParse(HttpContext.Current.Request[Parameter.Score], out Score);


                if (!string.IsNullOrWhiteSpace(Command))
                {
                    ZhangZhao.BLL.H_UserAvatarComment bll = new ZhangZhao.BLL.H_UserAvatarComment();

                    //添加评论
                    if (Command.Equals(CommandParameterValue.Add, StringComparison.CurrentCultureIgnoreCase))
                    {
                        bll.Add(new ZhangZhao.Model.H_UserAvatarComment()
                        {
                            CommentBody = CommentBody,
                            CommentTime = DateTime.Now,
                            CommentUserName = CommentUserName,
                            IsLike = IsLike,
                            IsRecommend = IsRecommend,
                            Score = Score,
                            UserAvatarId = UserAvatarId
                        });
                        s = Output.Success;
                    }
                    //删除评论
                    if (Command.Equals(CommandParameterValue.Delete, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (UserAvatarCommentId > 0)
                        {
                            bll.Delete(UserAvatarCommentId);
                            s = Output.Success;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                s = Output.Exception + ":" + ex.Message;
            }

            Response.Clear();
            Response.Write(s);
            Response.End();
        }
    }
}